#include "stdafx.h" #include "iostream" #include #include using namespace std; class PS { private: int tu,mau; public: friend ostream& operator<<( ostream& os,const PS &p) { os<>(istream& is, PS &p) { cout<<"\nNhap Tu so:";is>>p.tu; do { cout<<"\nNhap Mau so :"; is>>p.mau; } while(p.mau==0); return is; } int uscln(int x,int y); void rutgon(); PS operator+(PS); PS operator-(PS); PS operator*(PS); PS operator/(PS); }; int PS::uscln(int x,int y) { x=abs(x);y=abs(y); if(x*y==0) return 1; while(x!=y) if(x>y) x-=y; else y-=x; return x; } void PS::rutgon() { int x; x=uscln(tu,mau); tu=tu/x; mau=mau/x; } PS PS::operator+(PS q) { PS t; t.tu=tu*q.mau+mau*q.tu; t.mau=mau*q.mau; t.rutgon(); return t; } PS PS::operator-(PS q) { PS t; t.tu=tu*q.mau-mau*q.tu; t.mau=mau*q.mau; t.rutgon(); return t; } PS PS::operator*(PS q) { PS t; t.tu=tu*q.tu; t.mau=mau*q.mau; t.rutgon(); return t; } PS PS::operator/(PS q) { PS t; t.tu=tu*q.mau; t.mau=mau*q.tu; t.rutgon(); return t; } void main() { PS p,q,cong,tru,nhan,chia; cout<<"\n Nhap PS p: ";cin>>p; cout<<"\n PS p la : "<>q; cout<<"\n PS q la : "<